﻿Type.registerNamespace('FindNearTask');

FindNearTask = function(element) {
    FindNearTask.initializeBase(this, [element]);
    this._toolbar = null;
    this._divSelectionLayerID = null;
    this._hdnSearchAreaByTaskResultID = null;
};

FindNearTask.prototype = {
    initialize: function() {
        FindNearTask.callBaseMethod(this, 'initialize');
        this._toolbar.add_onToolSelected(Function.createDelegate(this, this._onToolSelected));
    },
    _onToolSelected: function(toolbarObject, activeToolInfo) {
        if (activeToolInfo.tool.name === 'SearchAreaBySelection') {
            $get(this._divSelectionLayerID).style.display = '';
        }
        else {
            $get(this._divSelectionLayerID).style.display = 'none';
        }
        // Update a hidden variable which keeps track of whether or not to search when task results node is clicked
        $get(this._hdnSearchAreaByTaskResultID).value = (activeToolInfo.tool.name === 'SearchAreaByTaskResult') ? 'true' : 'false';        
    },
    dispose: function() {
        FindNearTask.callBaseMethod(this, 'dispose');
    },
    get_toolbar: function() {
        return this._toolbar;
    },
    set_toolbar: function(value) {
        this._toolbar = value;
    },
    get_divSelectionLayerID: function() {
        return this._divSelectionLayerID;
    },
    set_divSelectionLayerID: function(value) {
        this._divSelectionLayerID = value;
    },
    get_hdnSearchAreaByTaskResultID: function() {
        return this._hdnSearchAreaByTaskResultID;
    },
    set_hdnSearchAreaByTaskResultID: function(value) {
        this._hdnSearchAreaByTaskResultID = value;
    }
};

FindNearTask.registerClass('FindNearTask', Sys.UI.Control);
